package com.li.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.li.mapper.MemberMapper;
import com.li.mapper.OrderMapper;
import com.li.service.ReportService;
import com.li.utils.DateUtils;
import freemarker.template.utility.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(interfaceClass=ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    MemberMapper memberMapper;
    @Autowired
    OrderMapper orderMapper;
    @Override
    public Map<String, Object> getBusinessReport() {
        Map<String,Object> map=new HashMap<>();
        //获取运营统计数据
        /*
                     reportDate:null,
                    todayNewMember :0,
                    totalMember :0,
                    thisWeekNewMember :0,
                    thisMonthNewMember :0,
                    todayOrderNumber :0,
                    todayVisitsNumber :0,
                    thisWeekOrderNumber :0,
                    thisWeekVisitsNumber :0,
                    thisMonthOrderNumber :0,
                    thisMonthVisitsNumber :0,
         */
        try {
            Date date = new Date();
            //获取当前日期
            String reportDate = DateUtils.parseDate2String(date);
            //获取今日新增会员数
            Integer todayNewMember = memberMapper.getMemberByDate(reportDate);
            //获取总会员数
            Integer totalMember = memberMapper.getTotalMember();
            //获取本周新增会员数
            Date firstDayOfWeek = DateUtils.getFirstDayOfWeek(date);
            Integer thisWeekNewMember = memberMapper.getMemberAfterDate(DateUtils.parseDate2String(firstDayOfWeek));
            //获取本月新增会员数
            Date firstDayOfMonth = DateUtils.getFirstDay4ThisMonth();
            Integer thisMonthNewMember = memberMapper.getMemberAfterDate(DateUtils.parseDate2String(firstDayOfMonth));
            //获取今天预约人数
            Integer todayOrderNumber = orderMapper.getOrderByDate(reportDate);
            //获取今天到诊人数
            Integer todayVisitsNumber = orderMapper.getVisitsCountByDate(reportDate);
            //获取本周预约人数
            Integer thisWeekOrderNumber = orderMapper.getOrderCountByAfterDate(DateUtils.parseDate2String(firstDayOfWeek));
            //获取本周到诊人数
            Integer thisWeekVisitsNumber = orderMapper.getVisitsCountByAfterDate(DateUtils.parseDate2String(firstDayOfWeek));
            //获取本月预约人数
            Integer thisMonthOrderNumber = orderMapper.getOrderCountByAfterDate(DateUtils.parseDate2String(firstDayOfMonth));
            //获取本月到诊人数
            Integer thisMonthVisitsNumber = orderMapper.getVisitsCountByAfterDate(DateUtils.parseDate2String(firstDayOfMonth));
            //获取热门套餐 name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222
            List<Map> hotSetmeal=orderMapper.getHotSetmeal();

            map.put("reportDate",reportDate);
            map.put("todayNewMember",todayNewMember);
            map.put("totalMember",totalMember);
            map.put("thisWeekNewMember",thisWeekNewMember);
            map.put("thisMonthNewMember",thisMonthNewMember);
            map.put("todayOrderNumber",todayOrderNumber);
            map.put("todayVisitsNumber",todayVisitsNumber);
            map.put("thisWeekOrderNumber",thisWeekOrderNumber);
            map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
            map.put("thisMonthOrderNumber",thisMonthOrderNumber);
            map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
            map.put("hotSetmeal",hotSetmeal);

            return map;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
